package top.callback.inf.beautyleaf.segment.dao;

import org.apache.ibatis.annotations.*;
import top.callback.inf.beautyleaf.segment.model.LeafTag;

import java.util.List;

/**
 * 标签 {@link LeafTag} 数据操作接口
 *
 * @author Pengyu Gan
 * CreateDate 2021/3/23
 */
public interface LeafTagMapper {

    /**
     * 获取所有的标签信息
     * @return 标签信息列表
     */
    @Select("SELECT id, tag_name, max_id, step, description, update_time FROM leaf_tag")
    @Results({
            @Result(column = "id", property = "id"),
            @Result(column = "tag_name", property = "tagName"),
            @Result(column = "max_id", property = "maxId"),
            @Result(column = "step", property = "step"),
            @Result(column = "description", property = "description"),
            @Result(column = "update_time", property = "updateTime"),
    })
    List<LeafTag> findAll();

    /**
     * 获取所有的标签名称
     * @return 标签名称列表
     */
    @Select("SELECT tag_name FROM leaf_tag")
    List<String> findAllTagNames();

    /**
     * 查询指定名称的标签
     * @param tagName 标签名称
     * @return 标签信息
     */
    @Select("SELECT id, tag_name, max_id, step, description, update_time FROM leaf_tag WHERE tag_name = #{tagName}")
    @Results({
            @Result(column = "id", property = "id"),
            @Result(column = "tag_name", property = "tagName"),
            @Result(column = "max_id", property = "maxId"),
            @Result(column = "step", property = "step"),
            @Result(column = "description", property = "description"),
            @Result(column = "update_time", property = "updateTime"),
    })
    LeafTag findByName(@Param("tagName") String tagName);

    /**
     * 变更指定名称的标签的 maxId
     * @param tagName 标签名称
     */
    @Update("UPDATE leaf_tag SET max_id = max_id + step WHERE tag_name = #{tagName}")
    void updateMaxId(@Param("tagName") String tagName);

    /**
     * 使用指定步长(step)变更指定名称的标签的 maxId
     * @param leafTag 标签信息
     */
    @Update("UPDATE leaf_tag SET max_id = max_id + #{step} WHERE tag_name = #{tagName}")
    void updateMaxIdBySpecificStep(LeafTag leafTag);

}
